import { IPSAppDEField } from '../../app/dataentity/ipsapp-defield';
import { IPSControl } from '../ipscontrol';
import { IPSDEFormMDCtrl } from './ipsdeform-mdctrl';
import { PSDEFormBaseGroupPanelImpl } from './psdeform-base-group-panel-impl';

export class PSDEFormMDCtrlImpl extends PSDEFormBaseGroupPanelImpl implements IPSDEFormMDCtrl {
  get buildInActions(): 1 | 2 | 4 {
    return this.M.buildInActions != null ? this.M.buildInActions : 0;
  }

  protected contentpscontrol: IPSControl | null = null;

  getContentPSControl(): IPSControl | null {
    if (this.contentpscontrol != null) return this.contentpscontrol;
    const value = this.M.getContentPSControl;
    if (value == null) {
      return null;
    }
    this.contentpscontrol = this.getPSModel4('control.IPSControl', value, 'getContentPSControl') as IPSControl;
    return this.contentpscontrol;
  }

  get contentPSControl(): IPSControl | null {
    return this.getContentPSControl();
  }

  getContentPSControlMust(): IPSControl {
    const value = this.getContentPSControl();
    if (value == null) {
      throw new Error('未指定内容部件');
    }
    return value;
  }

  get contentType(): 'LIST' | 'FORM' | 'GRID' | 'DATAVIEW' | 'REPEATER' {
    return this.M.contentType;
  }

  get fieldName(): string {
    return this.M.fieldName;
  }

  protected psappdefield: IPSAppDEField | null = null;

  getPSAppDEField(): IPSAppDEField | null {
    if (this.psappdefield != null) return this.psappdefield;
    const value = this.M.getPSAppDEField;
    if (value == null) {
      return null;
    }
    this.psappdefield = this.getPSModel4('app.dataentity.IPSAppDEField', value, 'getPSAppDEField') as IPSAppDEField;
    return this.psappdefield;
  }

  get psAppDEField(): IPSAppDEField | null {
    return this.getPSAppDEField();
  }

  getPSAppDEFieldMust(): IPSAppDEField {
    const value = this.getPSAppDEField();
    if (value == null) {
      throw new Error('未指定应用实体属性');
    }
    return value;
  }

  get resetItemName(): string {
    return this.M.resetItemName;
  }

  protected resetitemnames: string[] | null = null;

  getResetItemNames(): string[] | null {
    if (this.resetitemnames == null) {
      const value = this.M.resetItemNames;
      if (value == null) {
        return null;
      }
      const arrayNode: any[] = value;
      if (arrayNode.length == 0) {
        return null;
      }
      const list: string[] = [];
      for (let i = 0; i < arrayNode.length; i++) {
        list.push(arrayNode[i]);
      }
      this.resetitemnames = list;
    }
    return this.resetitemnames.length == 0 ? null : this.resetitemnames;
  }

  get resetItemNames(): string[] | null {
    return this.getResetItemNames();
  }

  get one2OneForm(): boolean {
    return this.M.one2OneForm != null ? this.M.one2OneForm : false;
  }

  get cls(): string {
    return 'PSDEFormMDCtrlImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.form.IPSDEFormMDCtrl') return true;
    return super.instanceof(cls);
  }
}
